package org.tgcloud.group.web.controller.manager;

import com.alibaba.fastjson.JSON;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.web.bind.annotation.*;
import org.tgcloud.group.core.APPResultMessage;
import org.tgcloud.group.core.ResultMessage;
import org.tgcloud.group.core.WXServiceUtils.SignUtil;
import org.tgcloud.group.core.session.Session;
import org.tgcloud.group.web.controller.req.sysLabel.SysLabelIdReq;
import org.tgcloud.group.web.websocket.WebSocketServer;

import java.util.HashMap;

/**
 * @author: zhy
 * @create: 2023-12-31 09:10
 * @description: 微信相关方法
 */
@Slf4j
@Api(tags = "微信相关方法")
@RestController
@RequestMapping("/manager/pc")
@EnableAutoConfiguration
public class WXController extends ManageAPPBaseController{


    @Autowired
    private WebSocketServer webSocketServer;


    @ApiImplicitParams({
    })
    @ApiResponses({
            @ApiResponse(code = 2000, message = "出现异常，及时通知后台")
    })
    @ResponseBody
    @GetMapping(value = "/getJSSDK")
    public APPResultMessage getJSSDK2(@RequestParam String url,
                                                       @ModelAttribute("session") Session session) throws Exception{
        APPResultMessage successMessage = APPResultMessage.getSuccessMessage();
        HashMap hashMap = SignUtil.jsSDK_Sign(url);
        logger.error("参数=======》" + JSON.toJSONString(hashMap));
        ResultMessage resultMessage = ResultMessage.builder().setData(hashMap);
        successMessage.setResult(resultMessage);
        return successMessage;
    }


    @ApiImplicitParams({
    })
    @ApiResponses({
            @ApiResponse(code = 2000, message = "出现异常，及时通知后台")
    })
    @ResponseBody
    @GetMapping(value = "/doSendWebSocketMsg")
    public APPResultMessage doSendWebSocketMsg(@RequestParam String msg){
        webSocketServer.sendMsgToAllWebUser(msg);
        APPResultMessage successMessage = APPResultMessage.getSuccessMessage();
        return successMessage;
    }

}
